Skip to content

Explicitly type convert metric values to Number(). #107

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

bobtfish
Copy link

Fixes #106

This is a suggested / potential fix for the issue in #106 where it's possible to submit correct looking metrics which are then interpreted as 0 by AWS because the value ends up quoted in the generated JSON

@@ -180,9 +180,9 @@ export class MetricsContext {
public putMetric(key: string, value: number, unit?: Unit | string): void {
const currentMetric = this.metrics.get(key);
if (currentMetric) {
currentMetric.addValue(value);
currentMetric.addValue(Number(value));
Copy link

@giancarlokc giancarlokc Jan 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bobtfish What do you think of throwing an exception if we find that value is not a number?
Javascript has weird/grey areas when it comes to parsing. It might make more sense to delegate the parsing to whoever is calling putMetric.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anything that isn’t just passing the value, quoting it and having cloudwatch silently drop it sounds fine to be honest.

I just didn’t want to make an API that currently fails silently start throwing exceptions, as that’s not a backwards compatible change (and so implies a new major version if semver is being used).

But if throwing an exception is the way that the AWS team wants to go then that’s fine with me!

@markkuhn markkuhn added the bug Something isn't working label Aug 5, 2022
@markkuhn markkuhn self-assigned this Aug 19, 2022
@markkuhn markkuhn linked an issue Sep 15, 2022 that may be closed by this pull request
@markkuhn markkuhn removed a link to an issue Sep 15, 2022
@markkuhn
Copy link
Contributor

Fixed by #135

@markkuhn markkuhn closed this Sep 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

String metric values are not rejected, but do not work.
3 participants